package com.qf.servlet;

import com.qf.pojo.Profile;
import com.qf.pojo.User;
import com.qf.service.loginservice;
import com.qf.service.serviceImpl.loginserviceImpl;
import com.qf.utils.StrUtils;
import org.apache.commons.beanutils.BeanUtils;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.lang.reflect.InvocationTargetException;
import java.util.List;
import java.util.Map;

@WebServlet("/login")
public class login extends BaseServlet {
    public String login(HttpServletRequest request, HttpServletResponse response){
        String username=request.getParameter("username");
        String password = request.getParameter("password");
       if(!StrUtils.empty(username)||!StrUtils.empty(password)){
            return "redirect:/login.jsp";
        }
        loginservice login=new loginserviceImpl();
        boolean logindo = login.logindo(username, password);
        if(logindo){
            return  "redirect:/record.jsp";
        }else {
            return "redirect:/login.jsp";
        }
    }
    public String register(HttpServletRequest request,HttpServletResponse response){
        String username=request.getParameter("username");
        String password = request.getParameter("password");
        if(!StrUtils.empty(username)||!StrUtils.empty(password)){
            return "redirect:/register.jsp";
        }
        loginservice login=new loginserviceImpl();
        int count = login.addser(username,password);
        if(count>0){
            return "redirect:/login.jsp";
        }else {
            return "redirect:/register.jsp";
        }
    }
    public  String all(HttpServletRequest request,HttpServletResponse response){
        loginservice all=new loginserviceImpl();
        List<Profile> list= all.All();
        request.setAttribute("record",list);
        return "forward:/record.jsp";
    }
}
